<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layuiAdmin 网站用户 iframe 框</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card" style="margin:15px">
        <div class="layui-card-body">
            <form class="layui-form">
                <div class="layui-tab layui-tab-brief">
                    <ul class="layui-tab-title">
                        <li class="layui-this">活动概述</li>
                        <li>活动时间</li>
                        <li>活动详情</li>
                    </ul>
                    <div class="layui-tab-content" >
                        <div class="layui-tab-item layui-show">
                            <div class="layui-form-item">
                                <label class="layui-form-label">申请人</label>
                                <div class="layui-input-inline">
                                    <input type="text" th:value="${session.admin.name}" readonly
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">活动标题</label>
                                <div class="layui-input-block">
                                    <input type="text" th:value="${meeting.title}" name="title" id="title"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">活动图片</label>
                                <div class="layui-input-inline">
                                    <input name="img" lay-verify="required" id="img" placeholder="图片地址"
                                           autocomplete="off" th:value="${meeting.img}" class="layui-input">
                                </div>
                                <div class="layui-input-inline layui-btn-container" style="width: auto;">
                                    <button type="button" class="layui-btn layui-btn-primary" id="uploadImg">
                                        <i class="layui-icon">&#xe67c;</i>上传图片
                                    </button>
                                    <button class="layui-btn layui-btn-primary" id="showImg">查看图片
                                    </button>
                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">开始时间</label>
                                <div class="layui-input-block">
                                    <input type="text" name="begin" id="begin" placeholder="请选择" th:value="${meeting.start}"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">结束时间</label>
                                <div class="layui-input-block">
                                    <input type="text" name="end" id="end" placeholder="请选择" th:value="${meeting.end}"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <div class="layui-form-item">
                                <label class="layui-form-label">活动类型</label>
                                <div class="layui-input-inline">
                                    <input type="text" value="讲座" readonly
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <hr class="layui-bg-gray">

                <div class="layui-form-item">
                    <label class="layui-form-label">话题内容</label>
                    <div class="layui-input-block" style="margin-right: 50px;">
        <textarea class="layui-textarea" id="content" name="content" lay-verify="content_desc" style="display: none">
            [[${meeting.content}]]
        </textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="button" class="layui-btn" id="updateHotActivity" value="立即提交">
                        <button class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script src="../../../layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['element','index', 'form', 'layer','laydate', 'layedit', 'upload'], function(){
        var $ = layui.$
            ,form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,element = layui.element
            ,upload = layui.upload ;

//日期定义
        laydate.render({
            elem : '#begin',
            type : 'datetime',
            format: 'yyyy-MM-dd HH:mm',
            done : function(value) {
                laydate.render({
                    elem : '#end',
                    type : 'datetime',
                    format: 'yyyy-MM-dd HH:mm',
                    min : value
                });
            }
        });
        //构建一个默认的编辑器
        layedit.set({
            uploadImage: {
                url: '/uploadByEdit' //接口url
                ,type: 'post' //默认post
            }
        });
        var index = layedit.build('content', {
            height: 180 //设置编辑器高度
        });
        form.verify({
            content_desc: function(value){
                layedit.sync(index);
            }
        });
        //console.log(layedit.getContent(index))
        console.log($("#content").val());
        var uploadSrc = upload.render({
            elem: '#uploadImg' //绑定元素
            , url: '/upload' //上传接口
            , done: function (res) {
                //上传完毕回调
                if (res.code == 200) {
                    $("#img").val(res.msg);
                    layer.msg('图片上传成功',
                        {
                            icon: 1,
                            time: 800
                        });
                } else {
                    layer.msg('图片上传失败');
                }
            }
            , error: function () {
                //请求异常回调
            }
        });
        var uploadInst = upload.render({
            elem: '#upload' //绑定元素
            , url: '/upload' //上传接口
            , done: function (res) {
                //上传完毕回调
                if (res.code == 200) {
                    $("#img").val(res.msg);
                    layer.msg('图片上传成功',
                        {
                            icon: 1,
                            time: 800
                        });
                } else {
                    layer.msg('图片上传失败');
                }
            }
            , error: function () {
                //请求异常回调
            }
        });

        $('#updateHotActivity').on('click', function () {
            //ajax提交
            var arr = new Array();
            $("input:checkbox[name='tag']:checked").each(function(i){
                arr[i] = $(this).val();
            });
            $.ajax({
                type: "post",
                url: "/updateHotActivity",
                data: {
                    "title":$("#title").val(),
                    "img":$("#img").val(),
                    "begin":$("#begin").val(),
                    "end":$("#end").val(),
                    "local":$("#local").val(),
                    "people":$("#people").val(),
                    "tag": arr.join(","),
                    "content":$("#content").val(),
                },
                dataType: 'json',
                success: function (data) {
                    if (data.code == 200) {
                        layer.msg('更新成功',
                            {
                                icon: 1,
                                time: 1000
                            }, function () {
                                layer.close(index); //关闭弹层
                                window.location.reload();
                            });
                    } else {
                        layer.msg("后台出错");
                    }
                }
            });
        });

        $('#showImg').on('click', function () {
            layer.photos(
                {photos: {title: "查看图片", data: [{src: $("#img").val()}]}, shade: .01, closeBtn: 1, anim: 5}
            )
            return false;
        });
    })
</script>
</body>
</html>